//
// Created by martin on 7/6/21.
//

#ifndef FTPSERVER_COMMON_H
#define FTPSERVER_COMMON_H

#include <stddef.h>
#include <sys/types.h>

#define MAXSIZE         1024
#define CLIENT_PORT     3306

typedef struct sockaddr SA;

int socket_create(const char *ip, const int port);
int socket_accept(int sock);
int socket_connect(const char *ip, const int port);
int recv_data(int sock, char *buf, int bufsize);
int send_response(int sock, int code);
void trimstr(char *str, int n);

int getlocalipaddr(char *ipbuf);

int send_reply(int sock, int code, const char *text);
int send_reply_multiline_middle(int sock, const char *text);
int send_reply_multiline_first(int sock, int code, const char *text);

ssize_t readn(int fd, void *ptr, size_t n);
ssize_t readline(int sock, void *ptr, size_t maxline);

#endif //FTPSERVER_COMMON_H
